/**
 * 
 * @brief  main.c
 * @param  None
 * 
 * @author xhq
 * @date   2024/10/30
 * 
 */
/* include */
#include "global_variables.h"
#include "bsp.h"
#include "app_thread_modules.h"
#include "bsp_interrupt.h"
#include "userHandler.h"
#include "rpmsg_modules.h"
#include "util_factory.h"

/* typedef */


/* define */


/* global varies*/


/* function */
/*****************************************************************************/
/**
*
* main
*
* @param	None.
*
* @return	None.
*
* @note		None.
*
*****************************************************************************/
int main(void)
{
    int32_t l_i32_error = 0;
    printf("MMW App Start!\n");

    /* init ini config */
    if (0 != (l_i32_error = sys_config_init(&g_sys_info.sys_config)))
    {
        printf("sys_config_init failed! error:%d\n", l_i32_error);
        return -1;
    }

    /* appsys 系统配置初始化 */
    if (0 != (l_i32_error = get_appsys_config(&g_sys_info.sys_config)))
    {
        printf("get_appsys_config failed! error:%d\n", l_i32_error);
        return -2;
    }

    /* create signal */
    if (0 != (l_i32_error = create_semaphore()))
    {
        printf("create_semaphore failed! error:%d\n", l_i32_error);
        return -3;
    }

    /* track info queue init */
    if (0 != (l_i32_error = queue_init(&g_track_info_queue)))
    {
        printf("queue_init g_track_info_queue failed! error:%d\n", l_i32_error);
        return -4;
    }

    /* dsp info queue init */
    if (0 != (l_i32_error = queue_init(&g_dsp_info_queue)))
    {
        printf("queue_init g_dsp_info_queue failed! error:%d\n", l_i32_error);
        return -4;
    }

    /* net init */
    if (0 != (l_i32_error = net_modules_init()))
    {
        printf("net_modules_init failed! error:%d\n", l_i32_error);
        return -5;
    }

    /* create first thread */
    if (0 != (l_i32_error = first_create_thread()))
    {
        printf("first_create_thread failed! error:%d\n", l_i32_error);
        return -6;
    }

    /* create second thread */
    if (0 != (l_i32_error = second_create_thread()))
    {
        printf("second_create_thread failed! error:%d\n", l_i32_error);
        return -6;
    }

    /* 数据处理初始化 */
    if (0 != (l_i32_error = data_process_modules_init()))
    {
        printf("data_process_modules_init failed! error:%d\n", l_i32_error);
        return -7;
    }

    /* rpmsg初始化 */
    if (0 != (l_i32_error = rpmsg_modules_init()))
    {
        printf("rpmsg_modules_init failed! error:%d\n", l_i32_error);
        return -8;
    }

    /* bsp init,内含保持进程存活的循环 */
    if (0 != (l_i32_error = bsp_init()))
    {
        printf("bsp_init failed! error:%d\n", l_i32_error);
        return -7;
    }

#ifdef FAR_RF_EN
     WaitFPGA_MipiDone(&pCfg[RC8088_RF_0]);
#endif
#ifdef NEAR_RF_EN
    WaitFPGA_MipiDone(&pCfg[RC8088_RF_1]);
#endif

    while(1)
    {
#ifdef FAR_RF_EN
        // /* 远端波形数据采集 */
        HAL_RC8088_WaveStart(&pCfg[RC8088_RF_0]);
        thread_mSleep(150);
#endif  
#ifdef NEAR_RF_EN
        /* 近端波形数据采集 */
        HAL_RC8088_WaveStart(&pCfg[RC8088_RF_1]);
        thread_mSleep(150);
#endif
    }

    
    return 0;
}
